<?php

class Involved_PurchaseResourceModel extends BaseModel
{
    protected $table = 'purchase_resource';//采购表
    //采购信息列表
    public  function PurchaseResource(){
       // $offset = ($paramObj->page-1) * HostEnum::PAGE_NUM;
        return  DB::table($this->table)
            ->select('purchase_id','title','spec','num','price','place','created','contacts','tell','company','sign','unit','address')
          //  ->skip($offset)->take(HostEnum::PAGE_NUM)
          ->where('state',1)
            ->orderBy('created','desc')
         ->paginate(10);
        //  ->get();
    }
    //个人中心采购信息列表
    public  function PurchaseResourceAdmin(){
        // $offset = ($paramObj->page-1) * HostEnum::PAGE_NUM;
        return  DB::table($this->table)
            ->select('purchase_id','title','spec','num','price','place','created','contacts','tell','company','sign','unit','address','state')
            //  ->skip($offset)->take(HostEnum::PAGE_NUM)
            ->where('user_id',session_get(UserEnum:: USER_INFO_USER_ID))
            ->orderBy('created','desc')
          ->get();
    }
    //个人中心采购列表删除
    public function PurchaseResourceDel($purchase_id){
        return DB::table($this->table)
            ->where(['purchase_id' =>$purchase_id])
            ->delete();
    }
    #采购查询
    public  function SelectPurchase($paramObj){
        $db = DB::table($this->table);
        if (!empty($paramObj->title)) {
            $db->where('title', 'like', "%{$paramObj->title}%");
        }
        if (!empty($paramObj->place)) {
            $db->where('place', 'like', "%{$paramObj->place}%");
        }
        return  $db
            ->select('title','spec','num','price','place','created','contacts','tell','company','sign','unit','address')
            ->where('state',1)
            ->orderBy('created','desc')
            ->paginate(10);
    }
    #发布采购
    public function AddPurchase(array $aData){
        return DB::table($this->table)->insert($aData);
    }

    //首页采购信息列表
    public  function IndexPurchaseResource(){
        // $offset = ($paramObj->page-1) * HostEnum::PAGE_NUM;
        return  DB::table($this->table)
            ->select('title','spec','num','price','place','created','contacts','tell','company','sign','unit','address')
            //  ->skip($offset)->take(HostEnum::PAGE_NUM)
            ->where('state',1)
            ->orderBy('created','desc')
            ->take(7)
            ->get();
    }

}
